package com.cssw.fyzb.busi.api.pay;

import com.cssw.fyzb.busi.service.pay.QuickPayService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.busi.util.EncryptUtil;
import com.cssw.fyzb.core.model.dodb.UserQuickSign;
import com.cssw.fyzb.core.model.vo.pay.UserQuickSignVo;
import com.cssw.fyzb.core.util.IdUtil;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: yangyiqun
 * @Date: 2020/7/14 22:10
 */

@Function(description = "获取快捷签约信息", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
})
@Component
public class GetQuickSign implements Action {

    private static final Logger logger = LoggerFactory.getLogger(GetQuickSign.class);

    @Autowired
    private QuickPayService quickPayService;

    @Autowired
    private UserService userService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");

        UserQuickSign userQuickSign = quickPayService.getUserQuickSignByUserId(userId);
        if (null != userQuickSign) {
            UserQuickSignVo vo = new UserQuickSignVo();
            vo.setQuickId(userQuickSign.getQuickId());
            vo.setUserId(userQuickSign.getUserId());
            vo.setBankName(userQuickSign.getBankName());
            vo.setCardNo(userQuickSign.getCardNo());
            vo.setMobile(userQuickSign.getMobile());
            vo.setUserName(userQuickSign.getRealName());
            vo.setIdCard(EncryptUtil.idEncrypt(userQuickSign.getIdCard()));
            return Response.success().put("data", vo);
        }
        return Response.success();
    }
}